var cc__decorate = __decorate;
Object.defineProperty(exports, "__esModule", {
  value: true
});
var $2GameUser = require("GameUser");
var $2EventCenter = require("EventCenter");
var $2EventDefine = require("EventDefine");
var $2AudioManager = require("AudioManager");
var $2UIManager = require("UIManager");
var $2UIPEnd = require("UIPEnd");
var $2UIVMain = require("UIVMain");
var $2Globe = require("Globe");
var $2UIPProp = require("UIPProp");
var $2UIPSetting = require("UIPSetting");
var $2GameConfiguration = require("GameConfiguration");
var $2UIPEndNew = require("UIPEndNew");
var cc__decorator = cc._decorator;
var ccp_ccclass = cc__decorator.ccclass;
var ccp_property = cc__decorator.property;
var def_levelbase = /* */function (_cc$Component39) {
  function _ctor() {
    var _this180;
    babel_classCallCheck(this, _ctor);
    _this180 = _callSuper(this, _ctor, arguments);
    _this180.victoryConditions = 0;
    _this180.bushu = 20;
    _this180.owner = null;
    _this180._loopaudio = {};
    _this180._loadingaudio = {};
    _this180.audiopath = "";
    _this180.playingnum = 0;
    _this180.waitaudio = false;
    return _this180;
  }
  babel_inherits(_ctor, _cc$Component39);
  return babel_createClass(_ctor, [{
    key: "onLoad",
    value: function onLoad() {
      $2EventCenter.default.regisEvent($2EventDefine.default.EVENT_GAME_VICTORY, this.gamevictory, this);
      $2EventCenter.default.regisEvent($2EventDefine.default.EVENT_GAME_FAIL, this.gamefail, this);
    }
  }, {
    key: "setOwner",
    value: function setOwner(e) {
      var t;
      this.owner = e;
      e && (null === (t = this.owner) || undefined === t || t.setDownCount(""));
    }
  }, {
    key: "onEnable",
    value: function onEnable() {}
  }, {
    key: "start",
    value: function start() {}
  }, {
    key: "gamefail",
    value: function gamefail() {
      var e = $2Globe.default.getInstance().currlv_range;
      if ($2GameConfiguration.default.getGFByType($2GameConfiguration.eGameFeatures.NewEnd)) {
        $2UIManager.UIManager.getInstance().showUI($2UIPEndNew.default, function (t) {
          null == t || t.setResult({
            win: 0,
            ratio: e
          });
        });
      } else {
        $2UIManager.UIManager.getInstance().showUI($2UIPEnd.default, function (t) {
          null == t || t.setResult({
            win: 0,
            ratio: e
          });
        });
      }
    }
  }, {
    key: "gamevictory",
    value: function gamevictory() {
      if ($2GameConfiguration.default.getGFByType($2GameConfiguration.eGameFeatures.NewEnd)) {
        $2UIManager.UIManager.getInstance().showUI($2UIPEndNew.default, function (e) {
          null == e || e.setResult({
            win: 1,
            ratio: 1
          });
        });
      } else {
        $2UIManager.UIManager.getInstance().showUI($2UIPEnd.default, function (e) {
          null == e || e.setResult({
            win: 1,
            ratio: 1
          });
        });
      }
    }
  }, {
    key: "levelUpdate",
    value: function levelUpdate(e) {}
  }, {
    key: "playSound",
    value: function playSound(e, t, n, o) {
      var _this181 = this;
      return new Promise(function (i) {
        "" == _this181.audiopath && (_this181.audiopath = _this181.node.name);
        var s = "levels/" + _this181.audiopath + "/audio/" + e;
        if (t) {
          if (null == _this181._loopaudio[e] && 1 != _this181._loadingaudio[e]) {
            _this181._loadingaudio[e] = 1, $2AudioManager.AudioManager.getInstance().playSound(s, t, n || 1, function (t) {
              _this181._loopaudio[e] = t;
              _this181._loadingaudio[e] = 0;
              i(t);
            }, o);
          }
        } else {
          $2AudioManager.AudioManager.getInstance().playSound(s, t, n, function (t) {
            if (_this181._loopaudio) {
              _this181._loopaudio[e] = t;
            } else {
              $2AudioManager.AudioManager.getInstance().stop(t);
            }
            i(t);
          }, o);
        }
      });
    }
  }, {
    key: "nostackPlaySound",
    value: function nostackPlaySound(e, t, n) {
      this.isplaying(e) || this.playSound(e, t, n);
    }
  }, {
    key: "playSoundSync",
    value: function playSoundSync(e) {
      var _this182 = this;
      this.beforePlaySound && this.beforePlaySound(e);
      return new Promise(function (t) {
        if ($2GameUser.default.getInstance().audio) {
          _this182.playSound(e).then(function (n) {
            _this182.afterPlaySound && _this182.afterPlaySound(e);
            if (-1 == n) {
              cc.log("找不到声音名字:", e);
              setTimeout(t, 2e3);
            } else {
              _this182.changeAudio(n, t);
            }
          });
        } else {
          _this182.afterPlaySound && _this182.afterPlaySound(e);
          t(true);
        }
      });
    }
  }, {
    key: "doTweenSync",
    value: function doTweenSync(e, t) {
      var n = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : .5;
      return new Promise(function (o) {
        cc.tween(e).to(n, t).call(o).start();
      });
    }
  }, {
    key: "isplaying",
    value: function isplaying(e) {
      if (this._loopaudio[e]) {
        var _t88 = $2AudioManager.AudioManager.getInstance().getState(this._loopaudio[e]);
        return _t88 == cc.audioEngine.AudioState.PLAYING || _t88 == cc.audioEngine.AudioState.INITIALZING;
      }
      return false;
    }
  }, {
    key: "pauseSystemEvents",
    value: function pauseSystemEvents() {
      this.node.pauseSystemEvents(true);
    }
  }, {
    key: "resumeSystemEvents",
    value: function resumeSystemEvents() {
      this.node.resumeSystemEvents(true);
    }
  }, {
    key: "update",
    value: function update(e) {
      $2UIManager.UIManager.getInstance().IsShow($2UIPProp.default) || $2UIManager.UIManager.getInstance().IsShow($2UIPSetting.default) || this.levelUpdate(e);
    }
  }, {
    key: "onDestroy",
    value: function onDestroy() {
      $2EventCenter.default.removeEvent($2EventDefine.default.EVENT_GAME_VICTORY, this.gamevictory, this);
      $2EventCenter.default.removeEvent($2EventDefine.default.EVENT_GAME_FAIL, this.gamefail, this);
    }
  }, {
    key: "stopAudio",
    value: function stopAudio(e) {
      if (this._loopaudio[e]) {
        console.log("停止播放：", e, this._loopaudio[e]);
        $2AudioManager.AudioManager.getInstance().stop(this._loopaudio[e]);
      }
      this._loopaudio[e] = undefined;
    }
  }, {
    key: "stopAudioAll",
    value: function stopAudioAll() {
      for (var _e101 in this._loopaudio) {
        this._loopaudio[_e101] && $2AudioManager.AudioManager.getInstance().stop(this._loopaudio[_e101]);
        this._loopaudio[_e101] = undefined;
      }
    }
  }, {
    key: "onDisable",
    value: function onDisable() {
      this.stopAudioAll();
    }
  }, {
    key: "complete",
    value: function complete() {
      var _this183 = this;
      this.victoryConditions--;
      if (this.victoryConditions <= 0) {
        this.node.pauseSystemEvents(true);
        this.playingnum = 0;
        if (this.waitaudio) {
          for (var _e102 in this._loopaudio) {
            if (this.isplaying(_e102)) {
              this.playingnum++;
              this.changeAudio(this._loopaudio[_e102], function () {
                _this183.playingnum--;
                0 == _this183.playingnum && _this183.scheduleOnce(function () {
                  _this183.gamevictory();
                }, .3);
              });
            }
          }
        }
        0 == this.playingnum && this.gamevictory();
      }
    }
  }, {
    key: "uncomplete",
    value: function uncomplete() {
      this.victoryConditions++;
    }
  }, {
    key: "addBushuPlayAd",
    value: function addBushuPlayAd(e) {
      var _this184 = this;
      $2UIManager.UIManager.getInstance().getUI($2UIVMain.default).levelPlayAD(function (t) {
        if (true === t) {
          _this184.bushu += 10;
          e();
        }
      });
    }
  }, {
    key: "touchEvent",
    value: function touchEvent(e) {
      if (e.type == cc.Node.EventType.TOUCH_START) {
        this.onTouchStartEvent(e);
      } else if (e.type == cc.Node.EventType.TOUCH_MOVE) {
        this.onTouchMoveEvent(e);
      } else {
        this.onTouchEndEvent(e);
      }
    }
  }, {
    key: "onTouchStartEvent",
    value: function onTouchStartEvent(e) {}
  }, {
    key: "onTouchEndEvent",
    value: function onTouchEndEvent(e) {}
  }, {
    key: "onTouchMoveEvent",
    value: function onTouchMoveEvent(e) {}
  }, {
    key: "showanswer",
    value: function showanswer() {}
  }, {
    key: "showMainUiTip",
    value: function showMainUiTip(e) {}
  }, {
    key: "randomposarr",
    value: function randomposarr(e, t) {
      var n = [];
      for (; t > 0;) {
        var _o161 = Math.floor(Math.random() * e);
        var _i42 = Math.floor(Math.random() * e);
        n.push(cc.v2(_o161, _i42));
        n.push(cc.v2(-_o161, -_i42));
        t--;
      }
      return n;
    }
  }, {
    key: "shake_position",
    value: function shake_position(e, t) {
      var n = e.length;
      this.schedule(function () {
        n--;
        t.setPosition(e[n]);
      }, .02, n - 1);
    }
  }, {
    key: "changeAudio",
    value: function changeAudio(e, t) {
      $2Globe.default.getInstance().changeAudio(this, e, t);
    }
  }, {
    key: "playPublicSound",
    value: function playPublicSound(e) {
      var t = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
      if (t) {
        $2AudioManager.AudioManager.getInstance().playBGM(e);
      } else {
        $2AudioManager.AudioManager.getInstance().playSound("Audio/".concat(e));
      }
    }
  }, {
    key: "newFuHuo",
    value: function newFuHuo(e) {
      e && e();
    }
  }]);
}(cc.Component);
def_levelbase = cc__decorate([ccp_ccclass], def_levelbase);
exports.default = def_levelbase;